<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>诉讼申请</title>
<jsp:include page="../../import.jsp" flush="true" />

</head>
<body class="iframeBody">
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
<div tabid="tabA" title="诉讼申请" lselected="true">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">客户名称</div>
                <div class="field">
                    <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
           <div class="fieldBox">
                <div class="label">合同号</div>
                <div class="field">
                    <input name="cntNo" id="cntNo" type="text" class="ui-textbox" value="">
                </div>
            </div>
             <div class="fieldBox">
                <div class="label">案件编号</div>
                <div class="field">
                    <input name="caseNo" id="caseNo" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_33" >
                <div class="label">立案时间</div>
                <div class="field">
                    <input name="registTmBegin" id="registTmBegin" type="text" class="ui-datepicker" value="">
                    <span>---</span>
                    <input name="registTmEnd" id="registTmEnd" type="text" class="ui-datepicker" value="">
                </div>
            </div>
            <div class="fieldBox"  >
                <div class="label">客户经理</div>
                <div class="field">
                    <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_33" id="searchPrjStsCdId">
                <div class="label">项目类型</div>
                <div class="field">
                    <select name="prjTypCd"  id="prjTypCd" >
                        <option value="" selected="selected">--请选择--</option>
                        <c:forEach items="${prjTypCdList}" var="opt">
                            <option value="${opt.code}">${opt.codeNm}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="sueStsCdBox">
                <div class="label">诉讼状态</div>
                <div class="field">
                    <select name="sueStsCd"  id="sueStsCd" >
                        <option value="" selected="selected">--请选择--</option>
                        <c:forEach items="${sueStsCdList}" var="opt">
                            <option value="${opt.code}">${opt.codeNm}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox" id="searchCstNmId">
                <div class="label">所属组织架构</div>
                <div class="field">
                    <input name="cstMgrOrgCd" id="cstMgrOrgCd" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn"  class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
            </div>
            </div>
    </form>
</div>

<div id="ligergrid1" class="sq-grid"></div> 
</div>
<div tabid="tabB" title="流程跟踪" id="tabBId">
	<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
</div>
</div>
</div>
<script type="text/javascript">

	var grid = null;
	var pageInApp={}; // to 下一级子窗口 接口
    var pageInTab=null;
	$(function () {
        initOrgTree();
        $("#searchBar").ligerForm();
        initTab();
        var params = {};//默认条件

        var form = liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            params[name]= data[name];
        }
        params.cstMgrOrgCd = "0000";
	   grid= $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/sue/sueApplyInfo/initApplyList.do',
            parms:params,
	    	method : 'get',
	        columns: [
	             { display: '客户', name: 'cstNm', align:'left',minWidth: 140 ,
	            	render: function (rowdata, rowindex, value, column) {
	            		var h = '';
	            			if(value&&value!="null"){
	            		    h+='<a href="javascript:cstDetail(';
	                        h+="'"+rowdata.cstId+"'";
	                        h+=')">'+value+'</a>'
	            			}
	                        return h;
                    },
                 enabledSort:true},
                { display: '合同号', name: 'cntNo', align:'left',minWidth: 140 ,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if(value&&value!="null"){
                            h+='<a href="javascript:cntLnk(';
                            h+="'"+rowdata.dataId+"',";
                            h+="'"+rowdata.dataTable+"'";
                            h+=')">'+value+'</a>'
                        }
                        return h;
                    },
                    enabledSort:true},
	             { display: '业务模式/业务类型', name: 'bizTypCdNm', minWidth: 140,align:'center', enabledSort:true},
	             { display: '项目类型/贷款类型', name: 'prjTypCdNm', minWidth: 140,align:'center', enabledSort:true},
	             { display: '机构', name: 'fundRasInsNm', width: 100 , enabledSort:true},
                 { display: '是否厂商业务', name: 'isSplMfr', width: 100 , enabledSort:true},
	             { display: '客户经理', name: 'cstMgrNm', width: 100 , enabledSort:true},
	             { display: '事业部', name: 'orgDispNm', width: 150, enabledSort:true},
	            { display: '敞口合计', name: '', minWidth: 140 , enabledSort:true,render:function(row){
	                return FormatMoney(row.open/100);
                    }},
	            { display: '案件编号', name: 'caseNo', minWidth: 100 , enabledSort:true},
	            { display: '立案时间', name: 'registTm', minWidth: 100 , enabledSort:true},
	            { display: '诉讼状态', name: 'sueStsCd', minWidth: 100 , enabledSort:true},
	            {
	                display: '操作', name: '', minWidth: 150 , enabledSort:true,
                    render:function(row){
                        return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="sueApply(' + row.applyId + ',' + row.dataId + ',\''+ row.dataTable +'\',\''+row.prjTypCd+'\');"><i class="sqBtnIco_49"></i>诉讼结案申请</a>  ';
                    }
                },
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'400',
	        heightDiff:-2,
            allowUnSelectRow: true,
            alternatingRow: false,
	        checkbox:true,
	        rownumbers:true,
            frozen:false,
            detail: {
               height: 'auto',
               onShowDetail: showDetail_grid
           }
	    });
        grid.setHeight(100);
        $("#searchBtn").click(reloadGrid);

	});
    function reloadGrid() {
        var form = liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        grid.reload();
    }
    /**
     * 诉讼申请按钮
     * @param applyId emmm 好像没啥用哦
     * @param dataId  数据ID
     * @param dataTable 数据表
     * @param prjTypCd 项目类型
     */
	function sueApply(applyId,dataId,dataTable,prjTypCd){
	    if(StringUtils.isNotEmpty(prjTypCd) && prjTypCd == "CDDYWYQ"){
            $.ligerDialog.error("YQ业务禁止发起诉讼申请！");
	        return;
        }
	    var url = "<%=path%>/sue/sueApplyInfo/checkSueApplyFLow.do";
	    var data = {dataId: dataId};
	    AjaxUtils.ajaxPost(url, data, function(result){
            // 若校验通过则可以发起新的流程
	        if (1 == result.success) {
                if ("PRJ_BSC_INFO" == dataTable) {
                    Add_navTab('sueApply' + dataId, '诉讼结案申请(设备账单)', "<%=path%>/sue/sueApplyInfo/toAddPage.do?dataId=" + dataId, reloadGrid);
                } else if ("MCR_BILL_M" == dataTable) {
                    Add_navTab('sueMcrApply' + dataId, '诉讼结案申请(小额贷)', "<%=path%>/sue/sueApplyInfo/toAddPage.do?dataId=" + dataId + "&dataTable=MCR_BILL_M", reloadGrid);
                }
            } else {
                $.ligerDialog.error(result.info);
            }

        })
    }
	var loadedTabs = [];
	//初始化Tab页签
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			onBeforeSelectTabItem: function(tabid) {
				var selectedRows = grid.getSelectedRows();
				if(tabid!="tabA"){
					if (selectedRows.length != 1) {
			             $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
			             return false;
			         }
				}
			},
			onAfterSelectTabItem: function(tabid) {
				var selectedRows = grid.getSelectedRows();
                var id = selectedRows[0].applyId;
				if(StringUtils.isEmpty(id)){
				    id="";
                }
                if(tabid!="tabA"){
					if (selectedRows.length != 1) {
			             $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
			             return false;
			         }else{
                        switch (tabid){
                            case "tabB":
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/sue/sueApplyInfo/toSueApplyFlowHisListPage.do?applyId="+id);
                                break;
                        }
							SetIframe_height();
						}
				}
			}
		});
		$.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
	};



	var detailGrid = null;
    //逾期明细列表
    function showDetail_grid(row, detailPanel, callback) {
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/sue/sueApplyInfo/initDtlList.do?dataId=' + row.dataId +'&dataTable=' + row.dataTable,
            method: 'get',
            columns: [
                {display: '支付表号', name: 'paySchNo', width: 160, align: 'left',
                    render: function (rowdata, index, value) {
                        if(null != rowdata.paySchNo && rowdata.paySchNo != '' && rowdata.tableNm=="PRJ_PRD_PAY_SCH_M"){
                            return '<a href="javascript:showPaySchDetail('+rowdata.paySchId+')"'+'class="link">'+rowdata.paySchNo+'</a>';
                        }else if(null != rowdata.paySchNo && rowdata.paySchNo != ''){
                            return rowdata.paySchNo;
                        }else{
                            return "";
                        }
                    }
                },
                { display: '支付表状态', name: 'prdStsCd', width: 150, enabledSort:true},
                { display: '逾期天数', name: 'overdueDay', minWidth: 150 , enabledSort:true},
                {
                    display: '逾期租金', name: 'overdueAmt', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueAmt / 100);
                    }
                },
                {
                    display: '剩余本金', name: 'leftS03', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.leftS03 / 100);
                    }
                },
                {
                    display: '剩余利息', name: 'leftS02', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.leftS02 / 100);
                    }
                },
                {
                    display: '敞口', name: 'open', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.open / 100);
                    }
                }
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            columnWidth: 100,
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    /**
     * 客户名称链接
     * @param cstId
     */
    function cstDetail(cstId){
        if(cstId){
            Add_navTab('cstDetail'+cstId,'客户信息',"<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id="+cstId);
        }else{
            $.ligerDialog.error('error')
        }
    }

    /**
     * 合同链接
     * @param dataId
     * @param dataTable
     */
    function cntLnk(dataId,dataTable){
        if(dataId && dataTable){
            if("PRJ_BSC_INFO" == dataTable){
                Add_navTab('cstDetail'+dataId,'项目信息',"<%=path%>/project/prjbscinfo/toModifyPage.do?fromPrjFlag=true&&id=" + dataId + "&&detailFlag=true");
            }else if("MCR_BILL_M" == dataTable){
                Add_navTab('cstDetail'+dataId,'小贷合同',"<%=path%>/mcr/mcrBillM/toBillDtlPage.do?id=" + dataId);
            }
        }else{
            $.ligerDialog.error('error')
        }
    }

    /**
     * 支付表链接
     * @param paySchId
     */
    function showPaySchDetail(paySchId){
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/risk/ovdCollect/getPayInfo.do?paySchId='+paySchId,
            success: function (msg) {
                if (msg.success == 1) {
                    Add_navTab('tab_prj_quat_prps'+paySchId,'查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId='+msg.data.prjId+'&id='+paySchId+'&prjPrdDtlId='+msg.data.prjPrdDtlId+'&prjPrdId='+msg.data.prjPrdId+'&detailFlag=true');
                }
            }
        });
    }

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
    function initOrgTree(){
        var params = {};
        <%--params.cstMgrOrgCd = '${currOrg}';--%>
        searchOrgTree = $("#cstMgrOrgCd").ligerComboBox({
            width: 480,
            selectBoxWidth: 480,
            selectBoxHeight: 150,
            //限制只能选叶节点，父节点不能点击
            treeLeafOnly: false,
            valueField: 'orgCd',
            textField: 'orgDispNm',
            showTreePath: true,
            tree: {
                ajaxType: 'get',
                idFieldName:'orgCd',
                textFieldName: 'orgDispNm',
                checkbox: false,
                parentIcon: "none",
                childIcon: "none",
                needCancel : false
            }
        });
        $.ajax({
            type: 'get',
            dataType:'json',
            data: params,
            url: '<%=path%>/project/prjbscinfo/searchBuOrgTree.do',
            success:function(msg){
                if(msg.success == 1){
                    searchOrgTree.treeManager.setData(msg.data);
                    searchOrgTree.clear();
                    searchOrgTree.setValue('0000');
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });

    }

  function clearBtn(){
    $("#searchBar").ligerForm();
			var form = new liger.get("searchBar");
			//form.clear(); 
			form.setData({
				cstNm:"",
                cntNo:"",
                caseNo:"",
                registTmBegin:"",
                registTmEnd:"",
                cstMgrNm:"",
                prjTypCd:"",
                cstMgrOrgCd:"0000",
                sueStsCd:""
			 });
	}
</script>

</body>
</html>